const express = require('express')
const mongoose = require('mongoose')
const DB_URL = 'mongodb://localhost:27017/react-app'
mongoose.connect(DB_URL)
mongoose.connection.on('connected', function(){
	console.log('mongo connect success')
})

const User = mongoose.model('user1', new mongoose.Schema({
	user: {type: String,require:true},
	age: {type: Number,require:true}
}))

User.create({
	user: 'react-app',
	age: 1
}, function (err, doc){
	if (!err) {
		console.log(doc)
	} else {
		console.log(err)
	}
})
const app = express()
app.get('/', function (req, res) {
	res.send('<h1>Hello world</h1>')
})

app.get('/data', function (req, res) {
	res.json({name: 'my-app', type: 'IT'})
})

app.listen(8000, function () {
	console.log('Node app start at port 8000')
})